﻿@model BcdFileDataViewModel
@{
    Layout = null;
    ViewBag.Title = "归档材料表首页";
}
<script type="text/javascript">
    var jgzl_gdcl_zTree;
    var setting = {
        treeObjId: "jgzl_gdcl_zTree",
        isSimpleData: true,              //数据是否采用简单 Array 格式，默认false
        treeNodeKey: "id",               //在isSimpleData格式下，当前节点id属性
        treeNodeParentKey: "pId",        //在isSimpleData格式下，当前节点的父节点id属性
        showLine: true,                  //是否显示节点间的连线
        checkable: false,                  //每个节点上是否显示 CheckBox
        callback: {
            nodeCreated: jgzl_gdcl_zTree_creat,    //这是节点生成时的回调函数
            click: jgzl_gdcl_zTree_click
        }
    };
    function jgzl_gdcl_zTree_creat(event, treeId, treeNode) {
        $("#" + treeNode.tId + "_a").attr("rel", "jgzl_gdcl_list");
    }
    function jgzl_gdcl_zTree_click(event, treeId, treeNode) {
        $("#CompletionMaterials_FileData_Create").attr("href", "/CompletionMaterials/FileData/Create?id=" + treeNode.id);
        $("#CompletionMaterials_FileData_Edit").attr("href", "/CompletionMaterials/FileData/Edit?id=" + treeNode.id);
        $("#jgzl_gdcl_list").loadUrl('/CompletionMaterials/FileData/Detail', "id=" + treeNode.id, null);
    }
    function DeleteFile() {
        var node = jgzl_gdcl_zTree.getSelectedNode();
        if (node.id != null) {
            alertMsg.confirm("您确定要删除吗？", {
                okCall: function () {
                    $.post("/CompletionMaterials/FileData/Delete", { "id": node.id }, refre_jgzl_gdcl_index, "json");
                }
            });
        }
    }
    function SonAndParentIds() {
        $.post("/CompletionMaterials/FileData/SonAndParentIds", "", refre_jgzl_gdcl_index, "json");
    }
    //刷新ztree
    function refre_jgzl_gdcl_index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            if (json.type == "add") {
                var pNode = null;
                if (json.pId != null)
                    pNode = jgzl_gdcl_zTree.getNodeByParam("id", json.pId);
                jgzl_gdcl_zTree.addNodes(pNode, { id: json.id, pId: json.pId, name: json.name }); //页面上添加节点  
                var node = jgzl_gdcl_zTree.getNodeByParam("id", json.id);
                jgzl_gdcl_zTree.selectNode(node);
                $("#CompletionMaterials_FileData_Create").attr("href", "/CompletionMaterials/FileData/Create?id=" + json.id);
                $("#CompletionMaterials_FileData_Edit").attr("href", "/CompletionMaterials/FileData/Edit?id=" + json.id);
                $("#jgzl_gdcl_list").loadUrl('/CompletionMaterials/FileData/Detail', "id=" + json.id, null);
                $.pdialog.closeCurrent();
            }
            if (json.type == "edit") {
                var node = jgzl_gdcl_zTree.getNodeByParam("id", json.id);
                node.name = json.name;
                jgzl_gdcl_zTree.updateNode(node);
                jgzl_gdcl_zTree.selectNode(node);
                $("#CompletionMaterials_FileData_Create").attr("href", "/CompletionMaterials/FileData/Create?id=" + json.id);
                $("#CompletionMaterials_FileData_Edit").attr("href", "/CompletionMaterials/FileData/Edit?id=" + json.id);
                $("#jgzl_gdcl_list").loadUrl('/CompletionMaterials/FileData/Detail', "id=" + json.id, null);
                $.pdialog.closeCurrent();
            }
            if (json.type == "delete") {
                var node = jgzl_gdcl_zTree.getNodeByParam("id", json.id);
                jgzl_gdcl_zTree.removeNode(node);
                $("#CompletionMaterials_FileData_Create").attr("href", "/CompletionMaterials/FileData/Create?id=0");
                $("#CompletionMaterials_FileData_Edit").attr("href", "/CompletionMaterials/FileData/Edit?id=0");
                $("#jgzl_gdcl_list").loadUrl('/CompletionMaterials/FileData/Detail', "id=0", null);
            }
        }
    }
    $(function () {
        $.getJSON(
           "/CompletionMaterials/FileData/GetFileDataJson",
           function (data) {
               jgzl_gdcl_zTree = $("#jgzl_gdcl_zTree").zTree(setting, data);
               $("#jgzl_gdcl_zTree").initUI();
           });
    });
</script>
<div class="panelBar">
    <ul class="toolBar">
        <li>@Html.PermissionButton("CompletionMaterials.FileData.Create", "CompletionMaterials_FileData_Create", "add", "/CompletionMaterials/FileData/Create?id=0", "new", "dialog", "添加", "true", "600", "520", "添加")</li>
        <li>@Html.PermissionButton("CompletionMaterials.FileData.Edit", "CompletionMaterials_FileData_Edit", "edit", "/CompletionMaterials/FileData/Edit?id=0", "new_edit", "dialog", "修改", "true", "600", "520", "修改")</li>
        <li>@Html.PermissionButton("CompletionMaterials.FileData.Delete", "CompletionMaterials_FileData_Delete", "delete", "javascript:DeleteFile();", "", "", "", "", "删除")</li>
        <li class="line">line</li>
        <li><a href="javascript:SonAndParentIds();" class="edit" style="display:none;"><span>更新父集合ID</span></a></li>
    </ul>
</div>
<div class="page" style="border-top: 1px solid #b8d0d6;" layouth="1">
    <div class="leftPanel" style="width: 300px;" layouth="28">
        <ul id="jgzl_gdcl_zTree" class="ztree"></ul>
    </div>

    <div id="jgzl_gdcl_list" style="margin-left: 301px; display: block;">
        @Html.Partial("Detail", Model.TheBcdFiledataInfo)
    </div>
</div>
